﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Dao;
using Core.Entity;
using System.Data;

namespace Core.Business
{
    public class BankBus
    {
        private BankDao dao;
        public BankBus() {
            dao = new BankDao();
        }

        public bool insert(Bank bank) {
            return dao.insert(bank);
        }

        public bool update(Bank bank) {
            return dao.update(bank);
        }

        public bool delete(int id) {
            return dao.delete(id);
        }

        public bool delete(String ids) {
            return dao.delete(ids);
        }

        public Bank get(int id) {
            DataTable dt = dao.get(id);
            Bank bank = new Bank();

            if (dt.Rows.Count > 0)
            {
                bank.Id = Convert.ToInt32(dt.Rows[0]["BNK_ID"]);
                bank.Name = dt.Rows[0]["BNK_NAME"].ToString();
                bank.Desc = dt.Rows[0]["BNK_DESC"].ToString();
            }
            return bank;
        }

        public List<Bank> getAll() {
            DataTable dt = dao.getAll();
            List<Bank> list = new List<Bank>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    Bank bank = new Bank();
                    bank.Id = Convert.ToInt32(dr["BNK_ID"]);
                    bank.Name = dr["BNK_NAME"].ToString();
                    bank.Desc = dr["BNK_DESC"].ToString();

                    list.Add(bank);
                }

            }
            return list;
        }
    }
}
